package com.zbkj.admin.controller;

import com.github.pagehelper.PageInfo;
import com.zbkj.admin.pojo.EbPaySecretKeyEntity;
import com.zbkj.admin.service.EbPaySecretKeyService;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import net.dreamlu.mica.core.result.R;
import org.springframework.web.bind.annotation.*;

/**
 * 第三方支付密钥管理
 */
@RestController
@RequiredArgsConstructor
@Tag(name = "第三方支付密钥管理")
@RequestMapping({"/api/admin/ebPaySecretKey"})
public class PaySecretKeyController {

    private final EbPaySecretKeyService ebPaySecretKeyService;

    /**
     * 获取密钥
     *
     * @param merchantPayNo 商户号
     * @return R
     */
    @Schema(description = "获取密钥")
    @GetMapping("/getSecretKey/{merchantPayNo}")
    public R<EbPaySecretKeyEntity> getSecretKey(@PathVariable("merchantPayNo") Long merchantPayNo) {
        return ebPaySecretKeyService.getSecretKey(merchantPayNo);
    }

    /**
     * 创建密钥
     *
     * @param ebPaySecretKeyEntity 密钥信息
     * @return R
     */
    @Schema(description = "创建密钥")
    @PostMapping("/createSecretKey")
    public R<Boolean> createSecretKey(EbPaySecretKeyEntity ebPaySecretKeyEntity) {
        return ebPaySecretKeyService.createSecretKey(ebPaySecretKeyEntity);
    }

    /**
     * 分页
     *
     * @param pageNo        当前页码
     * @param pageSize      每页数量
     * @param merchantPayNo 商户号
     * @param merchantName  商户名称
     * @return R
     */
    @Schema(description = "分页")
    @GetMapping("/page")
    public R<PageInfo<EbPaySecretKeyEntity>> page(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                                                  @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                  @RequestParam(value = "merchantPayNo", required = false) Long merchantPayNo,
                                                  @RequestParam(value = "merchantName", required = false) String merchantName) {
        return ebPaySecretKeyService.getPageInfo(pageNo, pageSize, merchantPayNo, merchantName);
    }

}
